from django import template

register=template.Library()	#固定变量名

@register.filter
def strlen_gt0(filedata):
    '''
        判断传入的字符串长度是否大于1 ；
        主要用于在技能题显示界面，判断是否有文件
    '''
    print('==============================', filedata)   # 110 测试
    if filedata:
        return True
    else:
        return False

@register.filter
def slice_str(str1, length):
    try:
        length = int(length)
        if len(str1) <= length:
            return str1
        else:
            return str1[: length] + '...'
    except Exception as e:
        return None


@register.filter
def cuttheme(str1):
    try:
        return str1.split('-')[1]
    except Exception as e:
        return None